package com.yangfan.thread.thread_wangwenjun09;

import java.util.LinkedList;

/**
 * @description: 请求队列
 * @author: yangfan
 * @date: Created in 2020/2/12 0012 14:27
 * @modified By:
 */
public class RequestServer {

    //保存请求的队列
    private LinkedList<Request> queue = new LinkedList<>();


    //获取请求
    public Request getRequest() {

        synchronized (queue){

            while (queue.size() <= 0) {
                try {
                    queue.wait();
                } catch (InterruptedException e) {
                    return null;
                }
            }

            return queue.removeFirst();
        }

    }


    //新增请求
    public void putRequest(Request request) {

        synchronized (queue) {

            queue.addLast(request);
            queue.notifyAll();

        }

    }


}
